/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package logic;

import gui.Splash;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JProgressBar;
import util.AudioPlayer;
import util.PreferencesPPM;

/**
 *
 * author: Pablo Martínez Piles
 */
public class SplashLogic implements PropertyChangeListener {

    private MainWindowLogic mw;
    private Splash splas;
    private JProgressBar barra;
    private PreferencesPPM ppm;

    public SplashLogic() {
        splas=new Splash(null, false,this);
        new AudioPlayer(System.getProperty("user.dir")+"/src/audio/macIni.wav").start();
        barra=splas.getJProgressoBarra();
        mw=new MainWindowLogic(this);
        ppm = new PreferencesPPM();
        mw.execute();
    }
    /**
     * Retorna el objeto Splash
     * @return
     */
    public Splash getSplas() {
        return splas;
    }

    /**
     * Escucha los cambios producidos en el panel principal
     * y cambia el porcentaje de la barra de carga.
     * @param evt
     */
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals("progress")) {
            int progress = (Integer) evt.getNewValue();
            splas.setEstado(mw.getEstadoCarga());
            barra.setValue(progress);
            if (progress == 100) {
                this.splas.dispose();
                barra.setIndeterminate(false);
            }
        }
    }

}
